package com.zs.ktsms.controller;

import com.zs.ktsms.pojo.SysRole;
import com.zs.ktsms.service.SysRoleService;
import com.zs.ktsms.utils.ResponseMessage;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/31 下午9:39
 */
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Resource
    private SysRoleService service;

    @GetMapping("/list")
    public ResponseMessage<List<SysRole>> select(){
        return ResponseMessage.success("角色列表加载成功",service.selectAll());
    }

    @PostMapping("/add")
    public ResponseMessage add(@RequestBody SysRole sysRole){
        int i = service.add(sysRole);
        if(i>0){
            return ResponseMessage.success("添加成功");
        }else{
            return ResponseMessage.error("添加失败");
        }
    }

    @GetMapping("/detail")
    public ResponseMessage detail(Integer id){
        return ResponseMessage.success("角色详情加载成功",service.detail(id));
    }

    @PostMapping("/update")
    public ResponseMessage update(@RequestBody SysRole sysRole){
        int i = service.update(sysRole);
        if(i>0){
            return ResponseMessage.success("修改成功");
        }else{
            return ResponseMessage.error("修改成功");
        }
    }

    @DeleteMapping("/del")
    public ResponseMessage delete(Integer id){
        int i = service.delete(id);
        if(i>0){
            return ResponseMessage.success("删除成功");
        }else{
            return ResponseMessage.error("删除成功");
        }
    }
}
